package com.example.expresscheck.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;

import com.example.expresscheck.R;
import com.example.expresscheck.db.AccountsDao;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AdapterSwitchAccount extends BaseAdapter {
	Context context;
	List<String> listLoginedAccout;
	String currentAccout;
	TextView tv;
	AccountsDao dao;
	SharedPreferences sp;

	public AdapterSwitchAccount(Context context) {
		this.context = context;
		dao = new AccountsDao(context);
		listLoginedAccout = dao.getListAccount();
		sp=context.getSharedPreferences("currentAccout", Context.MODE_PRIVATE);
		currentAccout = sp.getString("currentAccout", "");
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listLoginedAccout.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View itemView, ViewGroup arg2) {
		itemView = LayoutInflater.from(context).inflate(
				R.layout.item_switch_account, null);
		tv = (TextView) itemView.findViewById(R.id.textView1);
		String account = listLoginedAccout.get(position);
		tv.setText(account);
		if (account.equals(currentAccout)) {
			tv.setBackgroundColor(Color.BLUE);
		}
		return itemView;
	}

}
